package cn.stylefeng.guns.modular.recharge.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.recharge.entity.Recharge;
import cn.stylefeng.guns.modular.recharge.model.params.RechargeParam;
import cn.stylefeng.guns.modular.recharge.model.result.RechargeResult;
import cn.stylefeng.guns.modular.recharge.service.RechargeService;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 充值记录表控制器
 *
 * @author liuqiang
 * @Date 2020-02-09 12:03:07
 */
@RestController
@RequestMapping("/recharge")
public class RechargeController extends BaseController {

    @Autowired
    private RechargeService rechargeService;

    /**
     * 新增接口
     *
     * @author liuqiang
     * @Date 2020-02-09
     */
    @PostMapping("/addItem")
    public ResponseData addItem(@RequestBody RechargeParam rechargeParam) {
        this.rechargeService.add(rechargeParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuqiang
     * @Date 2020-02-09
     */
//    @RequestMapping("/editItem")
//    @ResponseBody
    public ResponseData editItem(RechargeParam rechargeParam) {
        this.rechargeService.update(rechargeParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuqiang
     * @Date 2020-02-09
     */
//    @RequestMapping("/delete")
//    @ResponseBody
    public ResponseData delete(RechargeParam rechargeParam) {
        this.rechargeService.delete(rechargeParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuqiang
     * @Date 2020-02-09
     */
//    @RequestMapping("/detail")
//    @ResponseBody
    public ResponseData detail(RechargeParam rechargeParam) {
        Recharge detail = this.rechargeService.getById(rechargeParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查看订单状态
     *
     * @author liuqiang
     * @Date 2020-02-09
     */
    @GetMapping("/getState")
    public ResponseData getState(RechargeParam rechargeParam) {
        if(StringUtils.isBlank(rechargeParam.getOrderNo())){
            throw new ServiceException(BizExceptionEnum.PARAM_MISSING.getCode(),"订单号不能为空");
        }
        RechargeResult detail = this.rechargeService.findByOrderNo(rechargeParam.getOrderNo());
        return ResponseData.success(detail);
    }
    /**
     * 查询列表
     *
     * @author liuqiang
     * @Date 2020-02-09
     */
    @GetMapping("/list")
    public LayuiPageInfo list(RechargeParam rechargeParam) {
        return this.rechargeService.findPageBySpec(rechargeParam);
    }

}


